package com.mj.factory.processFlow.Technology;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/8/29.
 */
@Controller
@RequestMapping("mjfactory/processFlow")
public class TechnologyController {
    @Autowired
    TechnologyService technologyService;
    private static Logger logger = Logger.getLogger(TechnologyController.class);

    /**
     * 查询所有的工艺实体
     * @return
     */
    @PostMapping(value = "getTechnologyList")
    @ResponseBody
//    @CheckPermission(permission={"mj_totalschedule:view"})
    public Map<String, Object> findAllTechnology() {
        Map<String, Object> map = new HashMap();
        List<Technology> list = technologyService.findAll();
        int length = technologyService.findAll().size();
        map.put("length", length);
        map.put("btns", list);
        return map;
    }


    /**
     * 添加工艺
     *
     * @param
     * @return
     */
    @RequestMapping(value = "addTechnology", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> addTechnology(Technology technology) {
        Map<String, Object> map = new HashMap();
        //默认状态为1(空闲)
        try {
            technologyService.save(technology);
            map.put("msg", "success");
        } catch (Exception e) {
            map.put("msg", "fail");
            logger.error(e);
        }
        return map;
    }
}
